package com.graduation.sports.ui.fragment;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import androidx.appcompat.app.AppCompatActivity;

import com.blankj.utilcode.util.ToastUtils;
import com.graduation.sports.R;
import com.graduation.sports.base.BaseFragment;
import com.graduation.sports.config.Session;
import com.graduation.sports.ui.activity.SportsActivity;
import com.graduation.sports.ui.widget.DialogFragmentUtil;
import com.lxj.xpopup.XPopup;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @ProjectName: sports
 * @Package: com.graduation.sports.ui.fragment
 * @ClassName: FoundFragment
 * @Description: java类作用描述
 * @Author: APC
 * @CreateDate: 2021/2/22 10:58
 * @Version: 1.0
 */
public class FoundFragment extends BaseFragment {

//    @BindView(R.id.up_btn_check)
//    ImageView btnCheck;
//    @BindView(R.id.found_new_add)
//    ImageView foundAdd;

    @BindView(R.id.rl_rope_skipping)
    RelativeLayout viewRopeSkipping;
    @BindView(R.id.rl_sit_and_reach)
    RelativeLayout viewSitAndReach;
    @BindView(R.id.rl_sargent_jump)
    RelativeLayout viewSargentJump;
    @BindView(R.id.rl_sit_up)
    RelativeLayout viewSitUp;
    @BindView(R.id.rl_standing_broad_jump)
    RelativeLayout viewStandingBroadJump;

    private String sportType = "";

    public static FoundFragment newInstance() {
        return new FoundFragment();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_found;
    }

    @Override
    protected void initEventAndData() {

        if (Session.getUserInfo().getGrade() > 3) {
            viewSitAndReach.setVisibility(View.GONE);
            viewSargentJump.setVisibility(View.GONE);
            viewSitUp.setVisibility(View.VISIBLE);
            viewStandingBroadJump.setVisibility(View.VISIBLE);
        } else {
            viewSitAndReach.setVisibility(View.VISIBLE);
            viewSargentJump.setVisibility(View.VISIBLE);
            viewSitUp.setVisibility(View.GONE);
            viewStandingBroadJump.setVisibility(View.GONE);
        }

//        btnCheck.setVisibility(View.GONE);
//        foundAdd.setVisibility(View.VISIBLE);

    }


//    R.id.found_new_add
    @OnClick({R.id.rl_rope_skipping, R.id.rl_sit_and_reach, R.id.rl_sargent_jump, R.id.rl_sit_up, R.id.rl_standing_broad_jump})
    public void onViewClicked(View view) {
        int id = view.getId();
        switch (id){
            case R.id.rl_rope_skipping:
                startSports("跳绳");
                break;
            case R.id.rl_sit_and_reach:
                startSports("坐位体前屈");
                break;
            case R.id.rl_sargent_jump:
                startSports("原地摸高");
                break;
            case R.id.rl_sit_up:
                startSports("仰卧起坐");
                break;
            case R.id.rl_standing_broad_jump:
                startSports("立定跳远");
                break;
//            case R.id.found_new_add:
////                DialogFragmentUtil.showAddSportPlanDialog((AppCompatActivity) getActivity());
//                showEditTextDialog();
//                break;
        }
    }

    private void startSports(String sportType){
        Intent intent = new Intent();
        intent.putExtra("sportType", sportType);
        intent.setClass(getActivity(), SportsActivity.class);
        startActivity(intent);
    }


    private void showEditTextDialog() {

        new XPopup.Builder(getContext())
                .hasStatusBarShadow(false)
                //.dismissOnBackPressed(false)
                .isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
                .autoOpenSoftInput(true)
                .isDarkTheme(true)
//                .setPopupCallback(new DemoXPopupListener())
//                        .autoFocusEditText(false) //是否让弹窗内的EditText自动获取焦点，默认是true
                //.moveUpToKeyboard(false)   //是否移动到软键盘上面，默认为true
                .asInputConfirm("请输入运动目标", null, null, "目标值",
                        text -> {
                            if (TextUtils.isEmpty(text)) {
                                ToastUtils.showShort("请输入目标运动量");
                                return;
                            }
                            int target = Integer.parseInt(text);
                            if (Session.getUserInfo().getGrade() == 0) {
                                if (target > 1000) {
                                    ToastUtils.showShort("当前年级，建议1公里以内/次");
                                    return;
                                }
                            }
                            if (Session.getUserInfo().getGrade() == 1) {
                                if (target > 2000) {
                                    ToastUtils.showShort("当前年级，建议2公里以内/次");
                                    return;
                                }
                            }
                            if (Session.getUserInfo().getGrade() == 2) {
                                if (target > 3000) {
                                    ToastUtils.showShort("当前年级，建议3公里以内/次");
                                    return;
                                }
                            }
                            if (Session.getUserInfo().getGrade() > 2) {
                                if (target > 5000) {
                                    ToastUtils.showShort("当前年级，建议5公里以内/次");
                                    return;
                                }
                            }

                        }).show();

    }

}
